package com.hoko.blur.processor;

import ohos.agp.components.Component;
import ohos.app.Context;
import ohos.media.image.PixelMap;

import com.hoko.blur.HokoBlur;
import com.hoko.blur.anno.Mode;
import com.hoko.blur.anno.Scheme;
import com.hoko.blur.api.IBlurBuild;
import com.hoko.blur.api.IBlurResultDispatcher;
import com.hoko.blur.task.AsyncBlurTask;

import java.util.concurrent.Future;

import static com.hoko.blur.task.AbliityBlurResultDispatcher.MAIN_THREAD_DISPATCHER;

/**
 * hoko模糊构建
 *
 * @author
 * @date 2021/08/03
 */
public class HokoBlurBuild implements IBlurBuild {

    /**
     * m模式
     */
    @Mode
    int mMode = HokoBlur.MODE_STACK;
    /**
     * m方案
     */
    @Scheme
    int mScheme = HokoBlur.SCHEME_NATIVE;
    /**
     * 米半径
     */
    int mRadius = 5;
    /**
     * 米样因素
     */
    float mSampleFactor = 5.0f;
    /**
     * m是力量复制
     */
    boolean mIsForceCopy = false;
    /**
     * 米需要高档
     */
    boolean mNeedUpscale = true;

    /**
     * m translatex
     */
    int mTranslateX = 0;
    /**
     * m translatey
     */
    int mTranslateY = 0;

    /**
     * m调度员
     */
    IBlurResultDispatcher mDispatcher = MAIN_THREAD_DISPATCHER;

    /**
     * m ctx
     */
    Context mCtx;

    /**
     * hoko模糊构建
     *
     * @param context 上下文
     */
    public HokoBlurBuild(Context context) {
        this.mCtx = context;
    }


    /**
     * 上下文
     *
     * @param context 上下文
     * @return {@link IBlurBuild}
     */
    @Override
    public IBlurBuild context(Context context) {
        this.mCtx = context;
        return this;
    }

    /**
     * 模式
     *
     * @param mode 模式
     * @return {@link IBlurBuild}
     */
    @Override
    public IBlurBuild mode(int mode) {
        this.mMode = mode;
        return this;
    }

    /**
     * 计划
     *
     * @param scheme 计划
     * @return {@link IBlurBuild}
     */
    @Override
    public IBlurBuild scheme(int scheme) {
        this.mScheme = scheme;
        return this;
    }

    /**
     * 半径
     *
     * @param radius 半径
     * @return {@link IBlurBuild}
     */
    @Override
    public IBlurBuild radius(int radius) {
        this.mRadius = radius;
        return this;
    }

    /**
     * 样本的因素
     *
     * @param sampleFactor 样本的因素
     * @return {@link IBlurBuild}
     */
    @Override
    public IBlurBuild sampleFactor(float sampleFactor) {
        this.mSampleFactor = sampleFactor;
        return this;
    }

    /**
     * 力副本
     *
     * @param isForceCopy 力复制
     * @return {@link IBlurBuild}
     */
    @Override
    public IBlurBuild forceCopy(boolean isForceCopy) {
        this.mIsForceCopy = isForceCopy;
        return this;
    }

    /**
     * 需要高档
     *
     * @param needUpscale 需要高档
     * @return {@link IBlurBuild}
     */
    @Override
    public IBlurBuild needUpscale(boolean needUpscale) {
        this.mNeedUpscale = needUpscale;
        return this;
    }

    /**
     * translatex
     *
     * @param translateX translatex
     * @return {@link IBlurBuild}
     */
    @Override
    public IBlurBuild translateX(int translateX) {
        this.mTranslateX = translateX;
        return this;
    }

    /**
     * translatey
     *
     * @param translateY translatey
     * @return {@link IBlurBuild}
     */
    @Override
    public IBlurBuild translateY(int translateY) {
        this.mTranslateY = translateY;
        return this;
    }

    /**
     * 调度程序
     *
     * @param dispatcher 调度程序
     * @return {@link IBlurBuild}
     */
    @Override
    public IBlurBuild dispatcher(IBlurResultDispatcher dispatcher) {
        mDispatcher = dispatcher;
        return this;
    }

    /**
     * 处理器
     *
     * @return {@link BlurProcessor}
     */
    @Override
    public BlurProcessor processor() {
        return BlurProcessorFactory.getBlurProcessor(mScheme, this);
    }

    /**
     * 模糊
     *
     * @param bitmap 位图
     * @return {@link PixelMap}
     */
    @Override
    public PixelMap blur(PixelMap bitmap) {
        BlurProcessor processor = processor();
        return processor.blur(bitmap);
    }

    /**
     * 模糊
     *
     * @param view 视图
     * @return {@link PixelMap}
     */
    @Override
    public PixelMap blur(Component view) {
        BlurProcessor processor = processor();
        return processor.blur(view);
    }

    /**
     * 异步模糊
     *
     * @param bitmap 位图
     * @param callback 回调
     * @return {@link Future}
     */
    @Override
    public Future asyncBlur(PixelMap bitmap, AsyncBlurTask.Callback callback) {
        BlurProcessor processor = processor();
        return processor.asyncBlur(bitmap, callback);
    }

    /**
     * 异步模糊
     *
     * @param view 视图
     * @param callback 回调
     * @return {@link Future}
     */
    @Override
    public Future asyncBlur(Component view, AsyncBlurTask.Callback callback) {
        BlurProcessor processor = processor();
        return processor.asyncBlur(view, callback);
    }

}
